﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using daSyntaxAnalyser.SyntaxTree;

namespace CQLQueries.SyntaxTree
{
    public class QueryNode
    {
        public object NodeTree;
        public object ValueDown;
        public object ValueUp;
        public object ElementUp;

        public SelectBlockNode SelectBlock;
        public WhereBlockNode WhereBlock;

        public QueryNode()
        {
        }

        public void Visit()
        {
            SelectBlock.NodeTree = NodeTree;
            SelectBlock.Visit();
            if (!CQL_Interpreter.Instance.t1)
            {                
                ValueUp = false;
                return;
            }
            NodeTree = SelectBlock.NodeTree;
            CQL_Interpreter.Instance.ownval = ElementUp;
            if (!(bool)SelectBlock.ValueUp)
            {
                ValueUp = false;
                return;
            }
            if (WhereBlock == null)
            {
                ValueUp = true;
                return;
            }
            WhereBlock.NodeTree = NodeTree;
            WhereBlock.Visit();
            if((bool)WhereBlock.ValueUp)
            {
                ValueUp = true;
            }
            else
            {
                ValueUp = false;
            }
        }
    }
}
